// ----------------------------------------------------------------------
//  Jack McCaffery
//  11-30-2014
// ----------------------------------------------------------------------

#include "topicModel/boundedParameters.H"
#include "topicModel/boundedParameters.H"

#include <QtTest/QtTest>

#include <iostream>
using namespace std;


/// \brief test class for basicData class
class BoundedParameters_test : public QObject
{

Q_OBJECT

private slots:

	/// \brief Initialize data for testing
	void initTestCase ();

	/// \brief Test general parameters functionality
	void testGradient ();

	/// \brief Cleanup after testing
	void cleanupTestCase ();

private:
	/// \brief Test parameters
	BoundedParameters<double> b;

	/// \brief Test parameters
	BoundedParameters<double> c;

	/// \brief Gradient to apply
	FixedParameters<double> gradient;
};

void BoundedParameters_test::initTestCase()
{
	b.getData ().resize (2, 3);
	b.setLowerBound (0);
	b.setUpperBound (1);

	b[0][0] = 0.5;
	b[0][1] = 0.7;
	b[0][2] = 0.1;
	b[1][0] = 0;
	b[1][1] = 0;
	b[1][2] = 0.9;

	c.getData ().resize (2, 3);
	c.setLowerBound (-1000);
	c.setUpperBound (100);

	c[0][0] = -100;
	c[0][1] = 100;
	c[0][2] = 20;
	c[1][0] = 1.5;
	c[1][1] = -700;
	c[1][2] = 0;

	gradient.getData ().resize (2, 3);

	gradient[0][0] = 1;
	gradient[0][1] = 2;
	gradient[0][2] = 3;
	gradient[1][0] = -10;
	gradient[1][1] = -7;
	gradient[1][2] = 20;
}

void BoundedParameters_test::testGradient()
{
	BoundedParameters<double> test;

	test = b;
	test.applyGradient (gradient, 0);

	QVERIFY (test == b);

	test = b;
	test.applyGradient (gradient, -0.1);

	QVERIFY (qFuzzyCompare (test[0][0], 0.4));
	QVERIFY (qFuzzyCompare (test[0][1], 0.5));
	QVERIFY (qFuzzyCompare (test[0][2], 0));
	QVERIFY (qFuzzyCompare (test[1][0], 1));
	QVERIFY (qFuzzyCompare (test[1][1], 0.7));
	QVERIFY (qFuzzyCompare (test[1][2], 0));

	test = c;
	test.applyGradient (gradient, -350);

	QVERIFY (qFuzzyCompare (test[0][0], -450));
	QVERIFY (qFuzzyCompare (test[0][1], -600));
	QVERIFY (qFuzzyCompare (test[0][2], -1000));
	QVERIFY (qFuzzyCompare (test[1][0], 100));
	QVERIFY (qFuzzyCompare (test[1][1], 100));
	QVERIFY (qFuzzyCompare (test[1][2], -1000));
}

void BoundedParameters_test::cleanupTestCase ()
{

}


QTEST_MAIN (BoundedParameters_test)
#include "boundedParameters_test.moc"
